package com.yayo.mangement.security.utils;

import com.yayo.mangement.info.UserInfo;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @SecurityUtil: Security工具类，
 * @author: Yayo
 * @date: 2022/9/3 23:54
 */
public class SecurityUtil {

    /**
     * 直接获取用户信息
     * @return
     */
    public static UserInfo getUser(){
        try{
            UserInfo userInfo =(UserInfo) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            return userInfo;
        } catch (Exception e){
            throw new RuntimeException("登录状态过期");
        }
    }
}
